package xyz.mumu233.robot.listenner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.forte.qqrobot.anno.Filter;
import com.forte.qqrobot.anno.Listen;
import com.forte.qqrobot.anno.depend.Beans;
import com.forte.qqrobot.beans.messages.msgget.PrivateMsg;
import com.forte.qqrobot.beans.messages.types.MsgGetTypes;
import com.forte.qqrobot.sender.MsgSender;
import com.forte.qqrobot.utils.CQCodeUtil;
import xyz.mumu233.robot.api.FeiFei;
import xyz.mumu233.robot.bean.Image;
import xyz.mumu233.robot.bean.api.feifei.FeiFeiResult;
import xyz.mumu233.robot.enums.MasterStatusEnum;
import xyz.mumu233.robot.mapper.ImageMapper;
import xyz.mumu233.robot.util.ConfigUtil;
import xyz.mumu233.robot.util.SpringContextUtil;


/**
 * @Author mumu
 * @create 2019/4/26 14:04
 */
@Beans
@Listen(MsgGetTypes.privateMsg)
public class MyMsgPrivateListener{

    private ImageMapper mapper = SpringContextUtil.getBean(ImageMapper.class);
    @Filter()
    public void onMessage(PrivateMsg msg, MsgSender sender, CQCodeUtil codeUtil){

        if((ConfigUtil.statusEnum == MasterStatusEnum.ZIBI)){
            QueryWrapper<Image> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("image_key","自闭");
            Image image = mapper.selectOne(queryWrapper);
            FeiFeiResult feiFeiResult = FeiFei.getReply(msg.getMsg());
            sender.SENDER.sendPrivateMsg(msg.getQQ(),codeUtil.getCQCode_image(image.getImagePath())+feiFeiResult.getContent());
         }else if(!(ConfigUtil.statusEnum == MasterStatusEnum.ONLINE)){
            sender.SENDER.sendPrivateMsg(msg.getQQ(),"你好我现在正在"+ConfigUtil.statusEnum.getContent()+"，有什么事情等会可以吗？");
        }
    }
}
